<?php 
/**
 * QFrameWork
 *
 * Entrance of all program.
 * 
 *
 * @author: quyang
 * @date: 2010-1-17
 * @version: 1.0
 */

define('DELIMITER', '/');
define('NL', "\r\n");
define('TAB', "\t");
define('EXT', ".php");
define('CORE_ROOT', dirname(__FILE__).DELIMITER);
define('SELF', basename(__FILE__));

//PHP settings.
ini_set('DISPLAY_ERRORS', 1);
error_reporting(E_ALL ^ E_NOTICE);

require (CORE_ROOT.'config'.DELIMITER.'global.php');
require (CORE_PATH.'predefine.php');
require (CORE_PATH.'core.php');

$oRouter = Loader::load_Lib('router');
$class = $oRouter->fetch_class();
$method = $oRouter->fetch_method();
$dir = $oRouter->fetch_directory();

if (!file_exists(CORE_CONTROLLOR.$dir.$class.EXT)) {
    throw new SystemError('Unable to load your default controller.  Please make sure the controller specified is valid.'.CORE_CONTROLLOR.$dir.$class.EXT);
}

require (CORE_CONTROLLOR.$dir.$class.EXT);

if (!class_exists($class) OR strtolower($method) == 'controller' OR strncmp($method, '_', 1) == 0 OR in_array(strtolower($method), array_map('strtolower', get_class_methods('Controller')))) {
    throw new NotFound404("No crack please :)");
}

$oInstance = new $class();

// is_callable() returns TRUE on some versions of PHP 5 for private and protected
// methods, so we'll use this workaround for consistent behavior
if (!in_array(strtolower($method), array_map('strtolower', get_class_methods($oInstance)))) {
    //show_404("{$class}/{$method}");
	throw new NotFound404("Not found Class/Method:{$class}/{$method}.");
}
// Call the requested method.
// Any URI segments present (besides the class/function) will be passed to the method for convenience
call_user_func_array(array(&$oInstance, $method), array_slice($oRouter->segments, 2));
?>